var initQuerySameTables = function(id,conditions,url,extendsColumn,index){
	var url_ = url ;
	if(_is_empty(url)){
		url_ = 'sys/LoanExt/list';
	}
	
var aoColumns = [
{
	"mDataProp" : "uid",
	"sTitle" : "匹配角色",
	"sDefaultContent" : "",
	"sClass" : "center",
	"mRender": function (data, display, row) {
        return '贷款申请单';
     }
}, {
	"mDataProp" : "loanBorrower",
	"sTitle" : "客户姓名",
	"sDefaultContent" : "",
	"sClass" : "center"
}, {
	"mDataProp" : "clientCardId",
	"sTitle" : "证件号码",
	"sDefaultContent" : "",
	"sClass" : "center"
}, {
	"mDataProp" : "loanCode",
	"sTitle" : "贷款申请号",
	"sDefaultContent" : "",
	"sClass" : "center"
},{
	"mDataProp" : "loanStatus",
	"sTitle" : "贷款状态",
	"bSortable": false,
	"sDefaultContent" : "",
	"sClass" : "center",
	"sWidth":"10%",
	"mRender": function (data, display, row) {
        return  parent.parent._local_loan_status[data]||'异常';
     }
}
	  ];

if(_is_not_empty(extendsColumn)){
	if(_is_empty(index)){
		aoColumns.splice(index, 0,extendsColumn); 
	}else{
		aoColumns.splice(2, 0,extendsColumn); 
	}
	
}
	
	$('#'+id).dataTable({
		"bProcessing" : true, //DataTables载入数据时，是否显示‘进度’提示
        "bServerSide" : true, //是否启动服务器端数据导入
        "bStateSave" : false, //是否打开客户端状态记录功能,此功能在ajax刷新纪录的时候不会将个性化设定回复为初始化状态
        "bJQueryUI" : true, //是否使用 jQury的UI theme
        "aLengthMenu" : [5, 10, 15], //更改显示记录数选项
        "iDisplayLength" : 5, //默认显示的记录数
        "bAutoWidth" : true, //是否自适应宽度 update\
        "bScrollCollapse" : false, //是否开启DataTables的高度自适应，当数据条数不够分页数据条数的时候，插件高度是否随数据条数而改变
        "bPaginate" : true, //是否显示（应用）分页器
        "bInfo" : true, //是否显示页脚信息，DataTables插件左下角显示记录数
        "sPaginationType" : "full_numbers", //详细分页组，可以支持直接跳转到某页
        "bSort" : false, //是否启动各个字段的排序功能
        "aaSorting" : [[1, "DESC"]], //默认的排序方式，第3列，升序排列
        "bFilter" : false, //是否启动过滤、搜索功能
        "sPaginationType": "full_numbers",
	    "sAjaxSource":url_,
        "fnServerData":function( sSource, aoData, fnCallback ) {
        	 aoData.push({'name':'beanProxy[enable]','value':0});
        	if(_is_not_empty(conditions)){
        		aoData = aoData.concat(conditions);
        	}
     	 
     	  //aoData.push({'name':'beanProxy[id_NotEqualTo]','value':_param_loan_id});
     	  //aoData.push({'name':'beanProxy['+conditionName+']','value':conditionValue});
	      $.ajax( {
	                type: "POST", 
	                url: sSource, 
	                cache : false,
	                dataType : "json",
	                data : aoData, 
	                success: function(resp) {
	                	if(resp && resp.state == 200){
	                		fnCallback(resp.datagrid);
	                		return false;
	                	}
	                	fnCallback(null);
	            }
	        });
},  
//自定义数据获取函数
		"aoColumns" : aoColumns,
		"oLanguage": {
            "sUrl":"static_resources/language/lang-cn.txt" //这个是国际化，也就是汉化的各种文字数据源，写对url就行了
        }
        
	});
	
};




$(function(){
	//先从数据库load一遍数据
	var loan;
		$.ajax({
	       	url:'sys/LoanExt/findByPk',
	    	data:{pks:_param_loan_id},
	    	type:'post',
	    	dataType:'json',
	    	async:false,
	    	success:function(result){
	    	        if(typeof(result)!='undefined'){
	    	        	loan = result;
	    	        }
	    		},
	    		complete:function(){
	    		}
	        });
		
		//相同名称
		
		initQuerySameTables('enterprise_same_name',[{'name':'beanProxy[id_NotEqualTo]','value':_param_loan_id},{'name':'beanProxy[loanBorrower]','value':loan['loanBorrower']}]);
		//相同证件号
		initQuerySameTables('enterprise_same_cardid',[{'name':'beanProxy[id_NotEqualTo]','value':_param_loan_id},{'name':'beanProxy[clientCardId]','value':loan['clientCardId']}]);
		//相同号码
//		if(_is_not_empty(loan['clientTel'])){
//			
//		}
		initQuerySameTables('enterprise_same_tel',[{'name':'beanProxy[loanId]','value':_param_loan_id},{'name':'beanProxy[clientMobile]','value':loan['clientTel']}],'sys/LoanExt/listBySameTel',{
			"mDataProp" : "clientTel",
			"sTitle" : "申请手机号",
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
		        return loan['clientTel'];
		     }
		});
		//相同地址
//		initQuerySameTables('enterprise_same_address','loanBorrower',loan['loanBorrower']);
		//相同单位
	//	initQuerySameTables('enterprise_same_unit','loanBorrower',loan['loanBorrower']);
		//相同单位地址
//		initQuerySameTables('enterprise_same_unit_address','loanBorrower',loan['loanBorrower']);
		
});
